package com.jml.zookeeper.二期.分布式锁;


public class OrderService implements Runnable {
    private OrderNumGenerator orderNumGenerator = new OrderNumGenerator();

    private Lock lock = new ZkTemplzateImplLock();

    @Override
    public void run() {
        getNumber();
    }

    private void getNumber() {
        try {
            lock.getLock();
            Thread.sleep(50);
            String number = orderNumGenerator.getNumber();
            System.out.println(Thread.currentThread().getName() + ",获取的number:" + number);

            // 如果zk超时了，有做数据库写的操作统一直接回滚
        } catch (Exception e) {

        } finally {
            lock.unLock();
        }
    }
    // ZkTemplzateImplLock父亲 模版类 AbstractTemplzateLock 父亲  Lock
}
